package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.utils.AliOssUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Controller
public class FileUploadController {
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        String originalFilename=file.getOriginalFilename();
        String Filename = UUID.randomUUID().toString() + originalFilename.substring(originalFilename.lastIndexOf("."));
//        String dir = "D:\\user\\Desktop\\新建文件夹";
//        String path = dir + File.separator + Filename;
//        file.transferTo(new File(path));
        String url = AliOssUtil.uploadFile(Filename, file.getInputStream());
        return Result.success("url");
    }
}
